package main

import (
	"flag"
	"fmt"

	"gitee.com/xchengli/blog-lib/config"
	"gitee.com/xchengli/blog-lib/search"
)

func main() {
	var action string
	flag.StringVar(&action, "action", "", "createIndex|mapping|indexAll|indexOne")
	flag.Parse()

	if action == "createIndex" {
		err := search.EsIndexCreate(config.EsConf["INDEX_NAME_POST"])
		if err != nil {
			fmt.Println(err)
		}

		return
	}

	if action == "delete" {
		err := search.EsIndexDelete(config.EsConf["INDEX_NAME_POST"])
		if err != nil {
			fmt.Println(err)
		}

		return
	}

	if action == "mapping" {
		search.EsIndexMapping(config.EsConf["INDEX_NAME_POST"], config.EsConf["INDEX_POST_MAPPING"])
		return
	}

	if action == "indexAll" {
		search.EsIndexAll()
		return
	}
}
